package com.mf.config;

import com.mf.interceptor.UserTokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: lmf
 * @Create: 2024/7/18 16:44
 * Description:
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public UserTokenInterceptor userTokenInterceptor() {
        return new UserTokenInterceptor();
    }

    /**
     * 向Spring MVC添加拦截器。
     *
     * @param registry 用于注册拦截器的InterceptorRegistry实例。
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将UserTokenInterceptor添加到拦截器链中
        registry.addInterceptor(userTokenInterceptor())
                // 拦截的路径
                .addPathPatterns("")
                // 排除的路径
                .excludePathPatterns("")
        ;
    }
}
